package org.hxyjs.service.impl;


import org.hxyjs.dao.ActivitytypeDao;
import org.hxyjs.dto.DTO;
import org.hxyjs.dto.MessageEnum;
import org.hxyjs.entity.Activitytype;
import org.hxyjs.entity.Activitytype;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.ActivitytypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service("ActivitytypeService")
public class ActivitytypeServiceImpl implements ActivitytypeService {
    @Resource
    ActivitytypeDao activitytypeDao;
    @Override
    public DTO<Activitytype> getAllActivitytypes()  throws Exception{
        List<Activitytype> activitytypes = activitytypeDao.getAllActivitytypes();
        MessageEnum messageEnum  = Optional.ofNullable(activitytypes).isPresent()?MessageEnum.GETACTIVITYPRIZESUCCESS: MessageEnum.GETACTIVITYPRIZEFAIL;
        return new DTO<Activitytype>(messageEnum.getCode(),messageEnum.getMessage(),activitytypes);
    }

    @Override
    public DTO<Activitytype> deleteActivitytypeByAtno(String atno)  throws Exception{
        Integer result = activitytypeDao.deleteActivitytypeByAtno(atno);
        MessageEnum messageEnum  =result> 0?MessageEnum.DELETEACTIVITYPRIZESUCCESS:MessageEnum.DELETEACTIVITYPRIZEFAIL;
        return new DTO<Activitytype>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Activitytype> updateActivitytypeByAtno(Activitytype activitytype)  throws Exception{
        Integer result = activitytypeDao.updateActivitytypeByAtno(activitytype);
        MessageEnum messageEnum  =result> 0?MessageEnum.UPDATEACTIVITYPESUCCESS:MessageEnum.UPDATEACTIVITYPRIZEFAIL;
        return new DTO<Activitytype>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Activitytype> addActivitytype(Activitytype activitytype) throws Exception {
        Integer result = activitytypeDao.addActivitytype(activitytype);
        MessageEnum messageEnum  = result> 0?MessageEnum.ADDACTIVITYPESUCCESS:MessageEnum.ADDACTIVITYPEFAIL;
        return new DTO<Activitytype>(messageEnum.getCode(),messageEnum.getMessage());
    }
    @Override
    public DTO<Activitytype> getActivitytypeByPage(PageInfo pageInfo ) throws Exception {
        List<Activitytype> activitytypes = activitytypeDao.getActivitytypeByPage(pageInfo);
        MessageEnum messageEnum  = Optional.ofNullable(activitytypes).isPresent()?MessageEnum.GETACTIVITYPRIZESUCCESS: MessageEnum.GETACTIVITYPRIZEFAIL;
        return new DTO<Activitytype>(messageEnum.getCode(),messageEnum.getMessage(),activitytypes,pageInfo);
    }
    
}
